mean_smooth <- function(lr_unit = 1, in_vec =  c()){
  out_vec <- rep(NA, length(in_vec))
  for(i in 1:length(in_vec)){
    if((i - lr_unit) < 1){
      start_cur <- 1
    }else{
      start_cur <- (i - lr_unit)
    }
    
    if((i + lr_unit) > length(in_vec)){
      end_cur <- length(in_vec)
    }else{
      end_cur <- (i + lr_unit)
    }
    out_vec[i] <- mean(in_vec[start_cur:end_cur])
  }
  return(out_vec)
}

# library(ggplot2)
# 
# 
# t_input <- rnorm(100, 50, 70)
# t_output1 <- mean_smooth(1, t_input)
# t_output2 <- mean_smooth(2, t_input)
# t_output3 <- mean_smooth(3, t_input)
# 
# id_vec <- rep(c("原始", "1单位中心", "2单位中心", "3单位中心"), each = 100)
# x_axis <- rep(1:100, 4)
# value_vec <-  c(t_input, t_output1, t_output2, t_output3)
# plot_df <- data.frame(x_axis, value_vec, id_vec)
# 
# ggplot(plot_df, aes(x = x_axis, y = value_vec, color = id_vec)) + 
#   geom_line(stat = "identity")
